// 通过编码范围生成对应的字符  =>放到数组中
var numList = [];
for (var i = 48; i <= 57; i++) {
    var char = String.fromCharCode(i);
    // console.log(char);
    numList.push(char);
}
//console.log(numList);

var bigList = [];
for (var i = 65; i <= 90; i++) {
    var char = String.fromCharCode(i);
    // console.log(char);
    bigList.push(char);
}
//console.log(bigList);

var smallList = [];
for (var i = 97; i <= 122; i++) {
    var char = String.fromCharCode(i);
    // console.log(char);
    smallList.push(char);
}
//console.log(smallList);

var speList = ["_", "$"]; //允许使用的特殊字符

var normalList = numList.concat(smallList, bigList, speList);
//console.log(normalList);

// normalList 存在 => 合法的
// normalList 不存在 => 非法的


function randCode() {
    var list = numList.concat(smallList, bigList);

    var str = "";
    for (var i = 0; i < 4; i++) {
        var index = Math.floor(Math.random() * list.length);
        var char = list[index];

        if (str.indexOf(char) == -1) {  // 判断字符串中是否存在该字符
            str += char;
        } else {
            i--;
        }

    }

    return str;

}

//
function loadGoods() {
    searchAllGoodsOrderLimit({
        key,
        orderCol,
        orderType,
        pageIndex,
        showNum
    }).then(data => {
        console.log(data);
        var {
            maxPage,
            count,
            list
        } = data;
        // 动态生成
        var html = "";
        list.forEach((item) => {
            var {
                goodsId,
                goodsName,
                goodsMsg,
                goodsPrice,
                goodsImg
            } = item;

            html += ` <li>
                <a href="./GoodsDetail.html?gid=${goodsId}">
                    <img class="goodsImg" src="${goodsImg}" alt="">
                    <p class="goodsName">${goodsName}</p>
                    <p class="goodsMsg">${goodsMsg}</p>
                    <p class="goodsPrice">
                        <span>
                            <w class="w">￥</w>${goodsPrice}
                        </span>
                    </p>
                </a>
            </li>`
        })
        $(".list ul").html(html);

    }).catch(err => {
        throw err;
    })
}